package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.Vip;
import com.lhy.vip.service.VipService;
import com.lhy.vip.mapper.VipMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【vip】的数据库操作Service实现
* @createDate 2024-07-28 12:27:01
*/
@Service
public class VipServiceImpl implements VipService{
    @Autowired
    private VipMapper iVipMapper;

    @Override
    public List<Vip> selectAll() {
        LambdaQueryWrapper <Vip> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Vip::getIsDelete,0);
        return iVipMapper.selectList(lqw);
    }


    @Override
    public List<Vip> selectList(Vip iVip) {
        LambdaQueryWrapper <Vip> lqw = this.lqw(iVip);
        return iVipMapper.selectList(lqw);
    }

    @Override
    public Integer insert(Vip iVip) {
        return iVipMapper.insert(iVip);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                Vip iVip = new Vip();
                iVip.setId(Long.parseLong(id));
                iVip.setIsDelete(1);
                iVipMapper.updateById(iVip);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(Vip iVip) {
        return iVipMapper.updateById(iVip);
    }

    @Override
    public Page<Vip> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Vip>)this.selectAll();
    }

    @Override
    public Page<Vip> pageList(Vip iVip, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Vip>)this.selectList(iVip);
    }

    @Override
    public List<Vip> isDelete() {
        LambdaQueryWrapper <Vip> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Vip::getIsDelete,1);
        return iVipMapper.selectList(lqw);
    }

    public LambdaQueryWrapper lqw(Vip iVip){
        LambdaQueryWrapper <Vip> lqw = new LambdaQueryWrapper<>();
        if (iVip.getId() != null){
            lqw.eq(Vip::getId,iVip.getId());
        }
        if (iVip.getVipName() != null){
            lqw.eq(Vip::getVipName,iVip.getVipName());
        }
        if (iVip.getNickName() != null){
            lqw.eq(Vip::getNickName,iVip.getNickName());
        }
        if (iVip.getTel() != null){
            lqw.eq(Vip::getTel,iVip.getTel());
        }
        if (iVip.getCreateTime() != null){
            lqw.eq(Vip::getCreateTime,iVip.getCreateTime());
        }
        if (iVip.getIntegral() != null){
            lqw.eq(Vip::getIntegral,iVip.getIntegral());
        }
        return lqw;
    }
}




